//一般直接写在一个js文件中
layui.use(['layer', 'form', 'element', 'carousel', 'flow'], function () {
    var layer = layui.layer
        , form = layui.form;
    var element = layui.element;
    var carousel = layui.carousel;
    var flow = layui.flow;


    //建造实例
    carousel.render({
        elem: '#test1'
        , width: '100%' //设置容器宽度
        , arrow: 'always' //始终显示箭头
        //,anim: 'updown' //切换动画方式
    });
    //监听table
    element.on('tab(blogType)', function (data) {
        let tid = $(this).attr("id");
        blogFolw(data.index,tid);
    });

    element.tabChange('blogType', "blogType_" + 0);;


    function blogFolw(index, tid) {
        flow.load({
            elem: '#LAY_demo'+index //流加载容器
            , scrollElem: '#LAY_demo2' //滚动条所在元素，一般不用填，此处只是演示需要。
            , isAuto: false
            , isLazyimg: true
            , done: function (page, next) { //加载下一页
                $.ajax({
                    url:"/article/flowArticle",
                    data:{tid:tid,pageIndex:1,token:$("#token").val()},
                    type:"GET",
                    dataType:"JSON",
                    success:function (data) {
                        var lis = [];
                        var list = data.dataList;
                        for(let i=0 ;i<list.length;i++ ){

                            let html = ' <div class="layui-col-md3 flow-ct">' +
                                '         <a href="/user/index/'+list[i].centerpath+'/'+list[i].uuid+'">  <img class="flow-img"  src=" '+list[i].cover+' "></a> '+
                                '' +
                                '                           <div  class="flow-info">' +
                                '                       <a href="/user/index/'+list[i].centerpath+'/'+list[i].uuid+'">   <h3>'+list[i].title+'</h3></a>' +
                                '                                 <p>'+list[i].summary+'</p>' +
                                '                                 <span>' +
                                '                                     <i class="layui-icon layui-icon-username"></i>' +
                                '                                     <a href="/client/user'+list[i].userId+'">'+list[i].userName+'</a>' +
                                '                                 </span>' +
                                '' +
                                '                                 <span>' +
                                '                                     阅读:'+list[i].reader+'' +
                                '                                 </span>' +
                                '                             </div>' +
                                '                       </div>';


                            lis.push(html)
                        }
                        next(lis.join(''), page < data.totalPage); //假设总页数为 6

                    },error:function () {
                        next("",page<0);
                    }

                });

            }
        });

    }


});